package experiment;

/**
 * @Author:云尚
 * @Description:
 */
public class Demo5 {
    // 反转数组
    public void reverse(int[] arr) {
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = temp;
        }
    }
    //数组排序
    public void sort(int[] arr) {
        //冒泡排序
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]) {
                    int temp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println();
    }
    //遍历数组
    public void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+"\t");
        }
    }
    //测试
    public static void main(String[] args) {
        Demo5 demo5= new Demo5();
        int[] arr = new int[]{1,2,3,4,5,7,0};
        demo5.reverse(arr);
        System.out.println("反转后：");
        demo5.print(arr);

        demo5.sort(arr);
        System.out.println("排序后：");
        demo5.print(arr);
    }
}
